//
//  CRequestCommand.h
//  collection
//
//  Created by 张靖 on 11-12-5.
//  Copyright (c) 2011年 collection. Inc.. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CURLLoaderProxy.h"

#define RESPONSE_ERROR_CODE_KEY         @"ErrorCode"
#define RESPONSE_CMDID_KEY              @"CMD"

#define kHttpRequestErrorNotification @"HTTPREQUESTERRORNOTIFICATION"

@protocol CRequestCommandDelegate;
@interface CRequestCommand : NSObject <CURLDataLoaderDelegate>
{
}

@property (nonatomic,assign) TUrlDataLoadErrorCode httpErrorCode;
@property (nonatomic,assign) id<CRequestCommandDelegate> delegate;

/////////////////////////
// 公返回数据字段
// 错误代码
// 命令代码
// 返回数据
/////////////////////////
@property (nonatomic,assign) int responseCode;
@property (nonatomic,assign) int commandID;

- (id) initWithDelegate:(id<CRequestCommandDelegate>)delegate;

- (void) startRequest:(NSString*)url postData:(NSDictionary*)postData;
- (void) startRequest:(NSString*)url postData:(NSDictionary*)postData header:(NSDictionary*)header;
- (BOOL) isRequesting;
- (void) stopRequest;

//在子类实现
- (void) parserDataInThread:(NSData*)recvData;
//默认实现是调用delegate的requestComplete方法
- (void) requestCompleteInMainThread;

@end


@protocol CRequestCommandDelegate <NSObject>

@optional
- (void) requestErrored:(CRequestCommand*)requestCommand;
@required
- (void) requestComplete:(CRequestCommand*)requestCommand;

@end
